package com.wholesale.beans;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.wholesale.utils.AsyncImageLoader;
import com.wholesale.utils.Constants;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

public class GoodsGallery {

	private int goodsId;
	private List<String> imgDescs;
	private List<String> imgOriginal;
	private List<Boolean> imgsync;
	private List<String> imgUrls;
	private List<String> thumbUrls;

	private List<Drawable> imageList = new ArrayList<Drawable>();
	private List<Bitmap> bitmapList;
	private JSONObject jsonObject;

	public List<Drawable> getImageDrawable() {
		return imageList;
	}

	public List<Bitmap> getBitmapList() {
		return bitmapList;
	}

	public int getGoodsId() {

		return goodsId;
	}

	public void setGoodsId(int goodsId) {

		this.goodsId = goodsId;
	}

	public List<String> getImgDescs() {

		return imgDescs;
	}

	public void setImgDescs(List<String> imgDescs) {
		this.imgDescs = imgDescs;
	}

	public List<String> getImgOriginal() {
		return imgOriginal;
	}

	public void setImgOriginal(List<String> imgOriginal) {
		this.imgOriginal = imgOriginal;
	}

	public List<Boolean> getImgsync() {
		return imgsync;
	}

	public void setImgsync(List<Boolean> imgsync) {
		this.imgsync = imgsync;
	}

	public List<String> getImgUrls() {
		return imgUrls;
	}

	public void setImgUrls(List<String> imgUrls) {
		this.imgUrls = imgUrls;
	}

	public List<String> getThumbUrls() {
		return thumbUrls;
	}

	public void setThumbUrls(List<String> thumbUrls) {
		this.thumbUrls = thumbUrls;
	}

	public void loadImage() {
		imageList = new ArrayList<Drawable>();
		for (String url : imgUrls) {
			Drawable drawable = AsyncImageLoader.loadImageFromUrl(url);
			if (drawable != null)
				imageList.add(drawable);
		}
	}

	public void loadBitmap() {
		bitmapList = new ArrayList<Bitmap>();
		for (String url : imgUrls) {
			// bitmapList.add(Constants.drawableToBitmap(AsyncImageLoader.loadImageFromUrl(url)));
			bitmapList.add(AsyncImageLoader.loadImageByUrl(url));
		}
	}

	public void jsonAnalytic(String jsonString) {

		try {
			jsonObject = new JSONObject(jsonString);
			jsonAnalytic(jsonObject);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void jsonAnalytic(JSONObject jsonObject) {
		this.jsonObject = jsonObject;
		try {
			goodsId = jsonObject.getInt("goodsId");
			imgDescs = new ArrayList<String>();
			imgOriginal = new ArrayList<String>();
			imgsync = new ArrayList<Boolean>();
			imgUrls = new ArrayList<String>();
			thumbUrls = new ArrayList<String>();
			JSONArray jsonArray = jsonObject.getJSONArray("imgUrls");
			int size = jsonArray.length();
			for (int i = 0; i < size; i++) {
				imgUrls.add(jsonArray.getString(i));
			}
			jsonArray = jsonObject.getJSONArray("imgDescs");
			size = jsonArray.length();
			for (int i = 0; i < size; i++) {
				imgDescs.add(jsonArray.getString(i));
			}
			jsonArray = jsonObject.getJSONArray("thumbUrls");
			size = jsonArray.length();
			for (int i = 0; i < size; i++) {
				thumbUrls.add(jsonArray.getString(i));
			}
			jsonArray = jsonObject.getJSONArray("imgsync");
			size = jsonArray.length();
			for (int i = 0; i < size; i++) {
				imgsync.add(jsonArray.getBoolean(i));
			}
			jsonArray = jsonObject.getJSONArray("imgOriginal");
			size = jsonArray.length();
			for (int i = 0; i < size; i++) {
				imgOriginal.add(jsonArray.getString(i));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}
